package ast.table

import ast.SqlNode
import ast.expr.SqlExpr
import ast.statement.select.SqlSelectQuery

/**
 * sql语法树：查询表父类
 * @property alias String? 表别名
 * @property columnAliasNames MutableList<String> 字段别名列表
 */
sealed class SqlTableSource(
    open var alias: String? = null,
    open val columnAliasNames: MutableList<String> = mutableListOf()
) : SqlNode

/**
 * sql语法树：普通查询表
 * @property tableName String 表名
 * @property alias String? 表别名
 * @property columnAliasNames MutableList<String> 字段别名列表
 */
data class SqlIdentifierTableSource(
    val tableName: String,
    override var alias: String? = null,
    override val columnAliasNames: MutableList<String> = mutableListOf()
) : SqlTableSource(alias)

/**
 * sql语法树：子查询表
 * @property select SqlSelectQuery 子查询语句
 * @property alias String? 表别名
 * @property columnAliasNames MutableList<String> 字段别名列表
 * @property isLateral Boolean 是否是LATERAL子查询
 */
data class SqlSubQueryTableSource(
    val select: SqlSelectQuery,
    override var alias: String? = null,
    override val columnAliasNames: MutableList<String> = mutableListOf(),
    var isLateral: Boolean = false
) :
    SqlTableSource(alias)

/**
 * sql语法树：JOIN查询表
 * @property left SqlTableSource JOIN左侧表
 * @property joinType SqlJoinType JOIN类型
 * @property right SqlTableSource JOIN右侧表
 * @property on SqlExpr? 连接条件
 * @property alias String? 表别名
 * @property columnAliasNames MutableList<String> 字段别名列表
 */
data class SqlJoinTableSource(
    val left: SqlTableSource,
    val joinType: SqlJoinType,
    val right: SqlTableSource,
    var on: SqlExpr? = null,
    override var alias: String? = null,
    override val columnAliasNames: MutableList<String> = mutableListOf()
) :
    SqlTableSource(alias)